package com.qifan.alb2b.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.ExchangeInfoDomain;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

@Repository
public class ExchangeInfoDao extends BaseDao{
	private static final Log logger=LogFactory.getLog(ExchangeInfoDao.class);
	public List<ExchangeInfoDomain> queryAll(){
		String sql="select * from exchangeInfo";
		return JdbcUtil.queryForList(this, ExchangeInfoDomain.class, sql);
	}
	
	/**
	 * 根据条件分页查询汇率信息
	 * @param dgm 分页参数
	 * @param uqp 管理员查询参数
	 * @return Page对象（分页信息&分页数据）
	 */
	public Page query(DataGridModel dgm,ExchangeInfoDomain uqp){
		logger.debug("查询汇率信息");
		/* 构建sql */
		StringBuilder sql=new StringBuilder();
		List<Object> params=new ArrayList<Object>();
		sql.append("select * from exchangeinfo where 1=1");
		if(uqp.getExchangeName()!=null&&!"".equals(uqp.getExchangeName())){
			sql.append(" and exchangeName like ?");
			params.add("%"+uqp.getExchangeName()+"%");
		}
		return super.queryObjByPage(sql.toString(), dgm.getRows(), dgm.getPage(), params, ExchangeInfoDomain.class);
	}
	
	public ExchangeInfoDomain getExchangeById(String id){
		String sql="select * from exchangeinfo where exchangeid=?";
		List<ExchangeInfoDomain> list= JdbcUtil.queryForList(this, ExchangeInfoDomain.class, sql, id);
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	
	/**
	 * 增加一个汇率信息
	 * @param ExchangeInfoDomain
	 */
	public void add(ExchangeInfoDomain exchangeInfoDomain){
		super.addObj(exchangeInfoDomain);
	}
	
	public void update(ExchangeInfoDomain exchangeInfoDomain){
		super.updateObj(exchangeInfoDomain, "exchangeId");
	}
	
	/**
	 * 批量删除
	 * @param ids
	 */
	public void delete(String[] ids){
		StringBuilder delSql=new StringBuilder();
		delSql.append("delete from exchangeinfo where exchangeId in(");
		for(int i=0;i<ids.length-1;i++){
			delSql.append("?,");
		}
		delSql.append("?)");
		this.getJdbcTemplate().update(delSql.toString(), ids);
	}
}
